﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.Net;
using System.IO;

namespace Chapter26.BasicWebClient
{
    /// <summary>
    /// BasicWebClientWindow.xaml 的交互逻辑
    /// </summary>
    public partial class BasicWebClientWindow : Window
    {
        public BasicWebClientWindow()
        {
            InitializeComponent();
            LoadWebSite();
        }

        private void LoadWebSite()
        {
            Task.Run(() =>
                {
                    var hao360Web = new WebClient();
                    var hao360Data = hao360Web.OpenRead("http://hao.360.cn");
                    var line = string.Empty;
                    using (var hao360DataReader = new StreamReader(hao360Data))
                    {
                        while ((line = hao360DataReader.ReadLine()) != null)
                        {
                            Dispatcher.Invoke(() => webClientListBox.Items.Add(line));
                        }
                    }
                });
        }
    }
}
